package com.example.android.apis.view;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Point;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;

public class CustomOverlay extends Overlay {
	private GeoPoint pointToDraw;
	private int resourceId;

	public CustomOverlay(GeoPoint pointToDraw, int resourceId) {
		super();
		this.pointToDraw = pointToDraw;
		this.resourceId = resourceId;
	}

	@Override
	public boolean draw(Canvas canvas, MapView mapView, boolean shadow,
			long when) {
		super.draw(canvas, mapView, shadow);

		Point screenPts = new Point();
		mapView.getProjection().toPixels(pointToDraw, screenPts);

		Bitmap bmp = BitmapFactory.decodeResource(mapView.getContext()
				.getResources(), resourceId);

		canvas.drawBitmap(bmp, screenPts.x - bmp.getWidth() / 2, screenPts.y
				- bmp.getHeight() / 2, null);
		return true;
	}
}
